{# Form macros. Native inputs with ``name`` attributes, so every form posts
or re-queries through htmx without client-side state.
{% from "components/macros/form.html" import field, text_input, select, date_input, primary_button %}
#}
{% from "components/macros/icons.html" import icon %}
{%- set _primary_button_classes -%}
text-sm text-aegis-text border border-aegis-teal bg-aegis-teal/10 rounded px-4 py-2.5 hover:bg-aegis-teal/20 transition-colors disabled:opacity-50 disabled:cursor-not-allowed inline-flex items-center justify-center gap-2
{%- endset -%}
{# Inline primary button (no loading spinner). Defaults to ``type="button"``
so it doesn't accidentally submit a form it's nested inside — pass
``type="submit"`` explicitly when you want submit semantics. ``attrs``
lets the caller pass arbitrary attributes (Alpine ``@click``,
``:disabled``, ``aria-*``) without bloating the macro signature. #}
{% macro primary_button(label, type="button", attrs="") %}
{% endmacro %}
{# Primary submit button with an inline loading spinner. Parent scope must
expose ``loading`` (bool) — typically flipped by ``@submit="loading = true"``
on the form. The button disables itself while loading so a double-click
can't double-submit. #}
{% macro submit_button(idle_label, loading_label) %}
{% endmacro %}
{# Shared input styling; every control below uses it so the bar reads as one. #}
{%- set _control_classes -%}
bg-aegis-bg border border-aegis-border rounded px-2.5 py-1.5 text-sm text-aegis-text placeholder:text-aegis-muted/50 focus:border-aegis-teal focus:outline-none transition-colors
{%- endset -%}
{# A native select. ``options`` are objects or dicts with ``id`` and
``name``, or, ``grouped``, ``{"label", "options"}`` groups of them (an
optgroup each); ``blank`` is the "no filter" label (``None`` for no
blank choice), chosen while nothing is; ``selected`` the current id.
``label`` wraps it inline for a filter bar; ``block`` lays it out
full-width inside a ``field()``. #}
{% macro select(name, options, selected=None, blank="All", label=None, block=False, grouped=False) %}
{% if label %}{% endif %}
{% endmacro %}
{% macro date_input(name, value=None, label=None, block=False) %}
{% if label %}{% endif %}
{% endmacro %}
{% macro checkbox(name, checked=False, label=None, value=None) %}
{% endmacro %}
{# A dropdown of checkboxes, posting ``name`` once per tick: a multi-pick
filter. ``options`` are dicts with ``value``, ``label``, ``checked`` and
an optional ``count``, and may carry their own ``name`` (a container under
its service, ``indent``ed). Kept across the swaps of the form it sits in
(``hx-preserve``, which needs the ``id``), so the menu stays open while
several are ticked; a click anywhere else closes it. The button at its
top ticks every option, or clears them when all are ticked, and the form
refreshes as for any tick. #}
{% macro checklist(id, name, label, options) %}
{% set ticked = options|selectattr("checked")|list|length %}
{{ label }}{% if ticked %}: {{ ticked }}{% endif %}
{{ error }}
{% endif %}